package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.service.ICategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "分类品牌")
@RestController
@RequestMapping("/categoryBrand")
public class CategoryBrandController extends BaseController {
    @Autowired
    ICategoryBrandService categoryBrandService;

    /**
     * 分类品牌分页
     *
     * @param categoryBrand
     * @return
     */
    @Operation(summary = "分页")
    @GetMapping("/list")
    public TableDataInfo queryCategoryBrandList(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrand> categoryBrandList = categoryBrandService.selectCategoryBrandList(categoryBrand);
        return getDataTable(categoryBrandList);
    }

    /**
     * 根据id获取详细信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "使用ID获取详细信息")
    @GetMapping("/{id}")
    public AjaxResult queryCategoryBrandById(@PathVariable("id") Long id) {
        return success(categoryBrandService.selectCategoryBrandById(id));
    }

    /**
     * 新增分类品牌
     *
     * @param categoryBrand
     * @return
     */
    @Operation(summary = "新增分类品牌")
    @PostMapping
    public AjaxResult addCategoryBrand(@RequestBody @Validated CategoryBrand categoryBrand) {
        return toAjax(categoryBrandService.insertCategoryBrand(categoryBrand));
    }

    /**
     * 修改分类品牌
     *
     * @param categoryBrand
     * @return
     */
    @Operation(summary = "修改分类品牌")
    @PutMapping
    public AjaxResult editCategoryBrand(@RequestBody @Validated CategoryBrand categoryBrand) {
        return toAjax(categoryBrandService.updateCategoryBrand(categoryBrand));
    }

    /**
     * 删除分类品牌
     *
     * @param ids
     * @return
     */
    @Operation(summary = "删除分类品牌")
    @DeleteMapping({"/{ids}"})
    public AjaxResult removeCategoryBrand(@PathVariable("ids") List<Integer> ids) {
        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }

    /**
     * 根据分类id获取品牌列表
     *
     * @param categoryId
     * @return
     */
    @Operation(summary = "根据分类id获取品牌列表")
    @GetMapping("/brandList/{categoryId}")
    public AjaxResult queryByCategoryId(@PathVariable("categoryId") Long categoryId) {
        return success(categoryBrandService.selectCategoryBrandByCategoryId(categoryId));
    }
}
